<?php

namespace App\Extensions\Renderable;


use App\Extensions\LinkRowAction;
use App\Extensions\Modal\ModalGrid;
use App\PatentApply;
use App\PatentAssess;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid\Displayers\Actions;
use Illuminate\Contracts\Support\Renderable;

class PatentAssessDetailRenderAble implements Renderable
{
    public function render($key = '')
    {
        $user = Admin::user();
        $grid = new ModalGrid(new PatentAssess());
        $grid->model()->collection(function ($collection) {
            foreach ($collection as $key => $item) {
                $item->index = $key + 1;
            }
            return $collection;
        });
        $grid->model()->where('patent_apply_id', $key)->where('state', 1);
        if ($user['role_type'] == 1) {
            $grid->column('expert.name', __('专家'))->style('white-space: nowrap;');
        } else {
            $grid->column('expert_name', __('专家'))->display(function () {
                return '专家' . $this->index;
            })->style('white-space: nowrap;');
        }
        $grid->column('score', __('评分'))->style('white-space: nowrap;');
        $grid->column('remark', __('评估意见'));
        if ($user['role_type'] == 1) {
            $model = PatentApply::query()->findOrFail($key);
            $grid->disableActions(false);
            $grid->actions(function (Actions $action) use ($model) {
                $action->disableDelete();
                $action->disableEdit();
                $action->disableView();
                $row = $action->row;
                $action->append(new LinkRowAction([
                    [file_custom_preview_url($row['path'], '(评估报告)' . $model['patent_name'], 'show'), '预览'],
                    [file_custom_preview_url($row['path'], '(评估报告)' . $model['patent_name']), '下载']
                ]));
            });
        }
        return $grid->render();
    }


}
